# def solve(arr):
#     lenth1 = len(arr) + 1
#     for i in range(len(arr)):
#         cur_sum = 0
#         for j in range(i, len(arr)):
#             sub_arr = arr[i:j + 1]
#             cur_sum += arr[j]
#             # print(sub_arr)
#             # print(sum(sub_arr))
#             if cur_sum >= 7:
#                 # print(sub_arr)
#                 lenth1 = min(lenth1, len(sub_arr))
#                 print(sub_arr, cur_sum)
#                 break
#     if lenth1 == len(arr) + 1:
#         return 0
#     else:
#         return lenth1
# #思路2
# #双指针之滑动窗口
# def solve(arr, target):
#     left = 0
#     right = 0
#     cur_sum = arr[left]
#     min_length1 = len(arr) + 1
#     while True:
#         if cur_sum < target:
#             right += 1
#             if right >= len(arr):
#                 break
#             cur_sum += arr[right]
#         else:
#             cur_length1 = right - left + 1
#             min_length1 = min(min_length1, cur_length1)
#             cur_sum -= arr[left]
#             left += 1
#             if left > right:
#                 break
#     if min_length1 == len(arr) + 1:
#         return -1
#     else:
#         return min_length1

# arr = [2, 3, 1, 2, 4, 3]
# print(solve(arr, 7))

#豆机器
# import random
# #参数为球的个数和槽子数
# def solve(balls, sluts):
#     #定义槽子数
#     arr = [0] * sluts
#     #几个球就执行几次
#     for _ in range(balls):
#         #每个球跳sluts一次
#         str = ""
#         count = 0
#         for j in range(sluts - 1):
#             r = random.randint(0,1)
#             if r == 0:
#                 str += "L"
#             else:
#                 str += "R" 
#                 count += 1
#         arr[count] += 1
#         print(str)
#     return arr


# balls, sluts = map(int, input().split(" "))
# arr = solve(balls, sluts)
# print(arr)
# import matplotlib.pyplot as plt
# plt.bar(list(range(sluts)), arr)
# plt.show()







#打印矩阵
def Pri(matrix):
    for i in range(len(matrix)):
        for j in range(len(matrix[0])):
            print(matrix[i][j], end = " ")
        print()

def is_lianxu(matrix, row, col):
    lenth_row = len(matrix)
    lenth_col = len(matrix[0])
    #向右
    if col <= lenth_col - 4:
        for i in range(col + 1, col + 4):
            if matrix[row][col] != matrix[row][i]:
                break
        else:
            print(matrix[row][col])
            return True

    #向下
    if row <= lenth_row - 4:
        for r in range(row + 1, row + 4):
            if matrix[row][col] != matrix[r][col]:
                break
        else:
            print(matrix[row][col])
            return True

    #向右下
    if col <= lenth_col - 4 and row <= lenth_row - 4:
        r = row + 1
        c = col + 1
        while r < row + 4 and c < col + 4:
            if matrix[row][col] != matrix[r][c]:
                break
            r += 1
            c += 1
        else:
            print(matrix[row][col])
            return True
    #向左下
    if row <= lenth_row - 4 and col >= 3:
        r = row + 1
        c = col - 1
        while r < row + 4 and c > col - 4:
            if matrix[row][col] != matrix[r][c]:
                break
            r += 1
            c -= 1
        else:
            print(matrix[row][col])
            return True
    return False


def solve(matrix):
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            if is_lianxu(matrix, i, j):
                return True
    return False


row, col = map(int, input().split(" "))
matrix = []
for i in range(row):
    rows = list(map(int, input().split(" ")))
    matrix.append(rows)


if solve(matrix):
    print("Yes")
else:
    print("No")
# Pri(matrix)